Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/network/src/commonMain/kotlin/org/meshtastic/core/network/transport/HeartbeatSender.kt renovate/net.java.dev.jna-jna-5.x (5a8f4966) Text, 2.32 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.network.transport

Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787org.meshtastic.proto.Heartbeat
Tff7b72import T7ee787org.meshtastic.proto.ToRadio
Tff7b72import T7ee787kotlin.concurrent.atomics.AtomicInt
Tff7b72import T7ee787kotlin.concurrent.atomics.ExperimentalAtomicApi

T8b949e/**
* Shared heartbeat sender for Meshtastic radio transports.
*
* Constructs and sends a `ToRadio(heartbeat = Heartbeat(nonce = ...))` message to keep the firmware's idle timer from
* expiring. Each call uses a monotonically increasing nonce to prevent the firmware's per-connection duplicate-write
* filter from silently dropping it.
*
* @param sendToRadio callback to transmit the encoded heartbeat bytes to the radio
* @param afterHeartbeat optional suspend callback invoked after sending (e.g. to schedule a drain)
* @param logTag tag for log messages
*/
Tff7b72class T56d364HeartbeatSenderTb4b4b4(
Tff7b72private Tff7b72val Te6edf3sendToRadioTb4b4b4: Tb4b4b4(Te6edf3ByteArrayTb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4,
Tff7b72private Tff7b72val Te6edf3afterHeartbeatTb4b4b4: Tb4b4b4(Te6edf3suspend Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4)Tff7b72? Tff7b72= Tff7b72nullTb4b4b4,
Tff7b72private Tff7b72val Te6edf3logTagTb4b4b4: Tffa657String Tff7b72= Ta5d6ff"Ta5d6ffHeartbeatSenderTa5d6ff"Tb4b4b4,
Tb4b4b4) Tb4b4b4{
Tf0883e@OptInTb4b4b4(Te6edf3ExperimentalAtomicApiTff7b72::Te6edf3classTb4b4b4)
Tff7b72private Tff7b72val Te6edf3nonce Tff7b72= Te6edf3AtomicIntTb4b4b4(T79c0ff0Tb4b4b4)

T8b949e/**
* Sends a heartbeat to the radio.
*
* The firmware responds to heartbeats by queuing a `queueStatus` FromRadio packet, proving the link is alive and
* keeping the local node's lastHeard timestamp current.
*/
Tf0883e@OptInTb4b4b4(Te6edf3ExperimentalAtomicApiTff7b72::Te6edf3classTb4b4b4)
Tff7b72suspend Tff7b72fun Td2a8ffsendHeartbeatTb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3n Tff7b72= Te6edf3nonceTb4b4b4.Te6edf3fetchAndAddTb4b4b4(T79c0ff1Tb4b4b4)
Te6edf3LoggerTb4b4b4.Te6edf3v Tb4b4b4{ Ta5d6ff"Ta5d6ff[Tffd700$Te6edf3logTagTa5d6ff] Sending ToRadio heartbeat (nonce=Tffd700$Te6edf3nTa5d6ff)Ta5d6ff" Tb4b4b4}
Te6edf3sendToRadioTb4b4b4(Te6edf3ToRadioTb4b4b4(Te6edf3heartbeat Tff7b72= Te6edf3HeartbeatTb4b4b4(Te6edf3nonce Tff7b72= Te6edf3nTb4b4b4)Tb4b4b4)Tb4b4b4.Te6edf3encodeTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3afterHeartbeatTff7b72?.Te6edf3invokeTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.05s